package com.spider.silence.job;

import com.spider.silence.downloader.BaiduForumDownloader;
import com.spider.silence.pool.BaiduForumDownLoaderPool;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

/**
 * Created by zh on 2017/1/22.
 */
public class BaiduForumJob implements StatefulJob {
   @Override
   public void execute(JobExecutionContext context) throws JobExecutionException {
       BaiduForumDownloader downloader = null;
       try{
           downloader = BaiduForumDownLoaderPool.getInstance().fetchDownLoader(1000);
           while (null == downloader) {
               System.out.println("第一次获取下载器失败, 定时器获取百度贴吧下载器");
               downloader = BaiduForumDownLoaderPool.getInstance().fetchDownLoader(1000);
           }
           downloader.initForums().generateTask();
       }catch (InterruptedException e){
           e.printStackTrace();
       }finally {
           BaiduForumDownLoaderPool.getInstance().releaseDownLoader(downloader);
       }

    }
}
